package org.nowcoder.leetcode.DP;

/**
 * Title  : 198. House Robber
 * Source : https://leetcode.cn/problems/house-robber/description/
 * Author : XrazYang
 * Date   : 2023-12-21
 */

public class LeetCode_198 {
    public int rob(int[] nums) {
        //1. 定义状态：dp[i] : 到第i户最大盗取金额
        int[] dp = new int[nums.length];

        //2. 初始状态
        dp[0] = nums[0];

        //3. 状态转移方程
        for (int i = 1; i < nums.length; i++) {
            if (i - 1 == 0) {
                dp[i] = Math.max(dp[i - 1], nums[1]);
            } else {
                dp[i] = Math.max(dp[i - 2] + nums[i], dp[i - 1]);
            }
        }
        return dp[nums.length - 1];
    }
}
